home *** CD-ROM | disk | FTP | other *** search
/ Libris Britannia 4 / science library(b).zip / science library(b) / INFO / DOSTIPS6.ZIP / DOSKYBD < prev    next >
Text File  |  1987-02-15  |  3KB  |  74 lines

  1.                       Shifting the Keyboard
  2.          (PC Magazine Vol 6 No 4 Feb 24, 1987 PC Tutor)
  3.  
  4.      You can turn CapsLock or NumLock on or off a various times from
  5. withing a program.  You might want to do this, for instance, if the
  6. program needed number input at some point, when you would turn on
  7. NumLock so the number pad is usable.
  8.      A single byte containing all shift state information is maintained
  9. by the PC's BIOS.  If you just need to look at this byte, you can get
  10. it by making an INT 16h call with AH equal to 2.  In most programming
  11. languages it's easier to fish it out of memory yourself.  If you want
  12. to change it, you must directory access the byte.  It is located at
  13. hex address 40:17.
  14.      Each of the 8 bits in this byte refer to the state of a different
  15. shift key.  If you think of bit 7 as the leftmost (or most significant)
  16. bit and bit 0 as the rightmost bit, here's what the 8 bits mean:
  17.  
  18.                  OR      AND
  19. Bit    A 1 means that:        Mask    Mask
  20.  
  21.  7    Insert is on        80    7F
  22.  6    CapsLock is on        40    BF
  23.  5    NumLock is on        20    DF
  24.  4    ScrollLock is on    10    EF
  25.  3    Alt key is down        08    F7
  26.  2    Ctrl key is down    04    FB
  27.  1    Left shift is down    02    FD
  28.  0    Right Shift is down    01    FE
  29.  
  30.      The "OR Mask" is a hex value that you can use to turn the shift
  31. sate on.  The "AND Mask" is a hex value that turns it off.  For
  32. instance, if you want to turn on NumLock, you would need to retrieve
  33. the shift state byte from memory, perform a logical OR with the hex
  34. value 20 (to turn the bit on), and store the value back into memory.
  35.      You can manipulate these bits in any programming language that
  36. allows you to access memory in segments outside your program.  In
  37. BASIC, you'd use DEF SEG, PEEK, and POKE.  In Turbo Pascal, you'd use
  38. the MEM array.  In assembly language or C, you'd use a far pointer.
  39. In a BASIC program, this code will turn on NumLock:
  40.  
  41. DEF SEG=&H40
  42. POKE &H17, &H20 OR PEEK (&H17)
  43.  
  44. In Turbo Pascal:
  45.  
  46. Mem [$40:$17] := Mem [$40;$17] OR $20 ;
  47.  
  48. In assembly language:
  49.  
  50. PUSH DS
  51. MOV  AX,40h
  52. MOV  DS,AX
  53. OR   BYTE PTR ds:[17h],20h
  54. POP  DS
  55.  
  56. In C:
  57.  
  58. * (char far *) 0x400017 |= 0x20
  59.  
  60. This last example assumes that your C compiler implements the "far"
  61. keyword the same way as Microsoft C, Versions 3 and 4.  In all these
  62. examples, hex addresses and values are used.  Note that each of these
  63. languages uses a different notation for hex.
  64.      To turn NumLock off, you can use similar code except that you want
  65. to set the bit to zero.  In all the examples above, replace 20 with DF.
  66. (In the assembly example, preface DF with a 0.)  In the BASIC, Turbo
  67. Pascal, and assembler examples, replace OR with AND.  In the C example,
  68. replace the OR operator (|) with an AND operator (&).
  69.      Changing the keyboard shift states from within a program is not
  70. always a good idea.  Even Lotus's 1-2-3 doesn't turn off NumLock.  It
  71. will tel you about it and request that you turn it off, but it won't
  72. turn it off itself.
  73.  
  74.